/**
 * Copyright (c) 2018 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package com.lswms.controller;

import com.lswms.annotation.Login;
import com.lswms.annotation.LoginUser;
import com.lswms.common.page.PageInfo;
import com.lswms.common.page.PageRequest;
import com.lswms.common.redis.RedisUtils;
import com.lswms.common.utils.Result;
import com.lswms.common.validator.ValidatorUtils;
import com.lswms.dto.YnUserDTO;
import com.lswms.dto.vo.req.DcLoginReq;
import com.lswms.dto.vo.req.DcQueryCreditReq;
import com.lswms.dto.vo.req.DcQueryReportReq;
import com.lswms.dto.vo.req.DcQueryStatusReq;
import com.lswms.dto.vo.req.LoginReq;
import com.lswms.dto.vo.req.UpdateUserInfoReq;
import com.lswms.dto.vo.resp.DcQueryCreditResp;
import com.lswms.dto.vo.resp.DcQueryReportResp;
import com.lswms.dto.vo.resp.GetAiResultResp;
import com.lswms.dto.vo.resp.LoginResp;
import com.lswms.dto.vo.resp.TradeListResp;
import com.lswms.dto.vo.resp.UpDateInfo;
import com.lswms.entity.YnUserEntity;
import com.lswms.redis.SysParamsRedis;
import com.lswms.service.YnDcLoginService;
import com.lswms.service.YnDcUserService;
import com.lswms.service.YnUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;





















import javax.servlet.http.HttpServletRequest;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import springfox.documentation.annotations.ApiIgnore;

import com.alibaba.fastjson.JSON;

/**
 * 用户接口
 *
 * @author Mark sunlightcs@gmail.com
 */
@RestController
@RequestMapping("/api/dcuser")
@Api(tags="DC用户接口")
@Slf4j
public class YnDcUserController {
	
    @Autowired
    private SysParamsRedis sysParamsRedis;
    
    @Autowired
    private YnDcLoginService ynDcLoginService;
    
    @Autowired
    private YnDcUserService ynDcUserService;


    /**
     * 登录、注册
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("login")
    @ApiOperation("登录、注册")
    public Result<LoginResp> dclogin(@RequestBody DcLoginReq dto,HttpServletRequest request){
        log.info("登录、注册：参数：{}",JSON.toJSONString(dto));
        LoginResp resp = ynDcLoginService.login(dto,request);
        log.info("登录、注册：返回：{}",resp);
        return new Result<LoginResp>().ok(resp);
    }
    
    /**
     * 获取信用升级信息
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("queryCreditInfo")
    @ApiOperation("获取信用升级信息")
    @Login
    public Result<DcQueryCreditResp> queryCreditInfo(@ApiIgnore @LoginUser YnUserEntity ynuser,HttpServletRequest request){
        log.info("获取信用升级信息：参数：{}",JSON.toJSONString(ynuser));
        DcQueryCreditResp uid = ynDcLoginService.queryCreditInfo(ynuser);
        log.info("获取信用升级信息：返回：{}",uid);
        return new Result<DcQueryCreditResp>().ok(uid);
    }
    /**
     * 信用升级后查询支付状态
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("queryPayStatus")
    @ApiOperation("信用升级后查询支付状态")
    public Result<Object> queryPayStatus(@RequestBody DcQueryStatusReq dto,HttpServletRequest request){
        log.info("信用升级后查询支付状态：参数：{}",JSON.toJSONString(dto));
        String result = ynDcLoginService.queryPayStatus(dto);
        log.info("信用升级后查询支付状态：返回：{}",result);
        return new Result<Object>().ok(result);
    }

    /**
     * 获取报告
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("queryReport")
    @ApiOperation("获取报告")
    @Login
    public Result<DcQueryReportResp> queryReport(@RequestBody DcQueryReportReq dto,
    		@ApiIgnore @LoginUser YnUserEntity ynuser,HttpServletRequest request){
        log.info("获取报告：参数：{}",JSON.toJSONString(dto));
        DcQueryReportResp result = ynDcLoginService.queryReport(dto,ynuser);
        log.info("获取报告：返回：{}",result);
        return new Result<DcQueryReportResp>().ok(result);
    }

    /**
     * 智能推荐获取结果
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("getAiResult")
    @ApiOperation("智能推荐获取结果")
    @Login
    public Result<GetAiResultResp> getAiResult(
    		@ApiIgnore @LoginUser YnUserEntity ynuser,HttpServletRequest request){
        log.info("GetAiResultResp：参数：{}",JSON.toJSONString(ynuser));
        GetAiResultResp result = ynDcLoginService.getAiResult(ynuser);
        log.info("GetAiResultResp：返回：{}",result);
        return new Result<GetAiResultResp>().ok(result);
    }
    /**
     * 借款记录
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("loanList")
    @ApiOperation("借款记录")
    @Login
    public Result<PageInfo<TradeListResp>> loanList(@RequestBody PageRequest dto,@ApiIgnore @LoginUser YnUserEntity ynuser,HttpServletRequest request){
    	log.info("借款记录，参数：dto:{},user:{}",JSON.toJSONString(dto),JSON.toJSONString(ynuser));
    	PageInfo<TradeListResp> resp = ynDcUserService.loanList(dto, ynuser);
        return new Result<PageInfo<TradeListResp>>().ok(resp);
    }

}